package com.intelligence.controller;

import com.intelligence.entity.model.SaveNewMenuFromRoleModel;
import com.intelligence.entity.result.Result;
import com.intelligence.entity.result.ResultCodeEnum;
import com.intelligence.service.SysPermissionService;
import com.intelligence.service.SysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * @Author : RulerWood
 * @Data : 2024/5/17 - 14:53
 */
@Tag(name = "角色管理")
@RestController
@RequestMapping("/intelligence-user/role")
public class RoleController {
    @Autowired
    private SysRoleService sysRoleService;
    @Autowired
    private SysPermissionService sysPermissionService;

    /**
     * 用户菜单回显
     *
     * @param roleId 角色id
     * @return
     */
    @GetMapping(value = "/findSysRolePermissionByRoleId/{roleId}")
    @Operation(summary = "用户菜单回显")
    public Result<Map<String, Object>> findSysRoleMenuByRoleId(@PathVariable(value = "roleId") Long roleId) {
        Map<String, Object> sysRoleMenuList = sysPermissionService.findSysRoleMenuByRoleId(roleId);
        return Result.build(sysRoleMenuList, ResultCodeEnum.SUCCESS);
    }

    /**
     * 保存该角色新的菜单权限
     *
     * @param saveNewMenuFromRoleModel 角色主键，菜单主键List集合
     * @return
     */
    @PostMapping("/saveNewMenuFromRole")
    @Operation(summary = "保存该角色新的菜单权限")
    public Result saveNewMenuFromRole(@RequestBody SaveNewMenuFromRoleModel saveNewMenuFromRoleModel) {
        sysRoleService.saveNewMenuFromRole(saveNewMenuFromRoleModel);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


}
